package com.aop.demo.web;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class HelloController {

	/**
	 * 返回view
	 */
	@RequestMapping("/hi")
    public String sayHi() {
        return "hi";
    }
	
	@RequestMapping("/view")
    public ModelAndView returnView() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("view");
        modelAndView.addObject("key", "return view");
        return modelAndView;
    }
	
	/**
	 * 静态模板你还想返回static中的页面，那么就要用重定向：
	 */
	@RequestMapping("/redirect")
	public String redirect() {
		return "redirect:redirect.html";  
	}
	
	/**
	 * 访问templates中页面
	 */
	@RequestMapping("/noRedirect")
	public String noRedirect() {
		return "redirect.html";
	}
	
	/**
	 * 返回json
	 * 使用@ResponseBody
	 */
	@RequestMapping("/json")
	@ResponseBody
	public String returnJson() {
		return "使用@ResponseBody 返回json";
	}
}
